#ifndef SPLITIMGTOPT_H
#define SPLITIMGTOPT_H
#include <QObject>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
using namespace cv;
using namespace std;
class splitImgToPt : public QObject
{
    Q_OBJECT
public:
    explicit splitImgToPt(QObject *parent = nullptr);
signals:
public slots:
private:
    int idx;//调用次数
    //左边截取线
    int XoffsetL;
    long double angleL;//弧度
    //右边截取线
    int XoffsetR;
    long double angleR;//弧度
    const int Yoffset = 1079;
    cv::Vec4f line1;
    cv::Vec4f line2;
    //角点集合
    std::vector<vector<cv::Point>> pointArr;
    bool flag;
public:
    splitImgToPt(const int XoffsetLT, const int XoffsetRT)
        :idx(0), flag(false),pointArr(std::vector<vector<cv::Point>>(6, vector<Point>(5)))
    {

        XoffsetL = XoffsetLT;
        XoffsetR = XoffsetRT;
        if(flag==false)
        {
            cout<<"splitImgToPt lines not initialize"<<endl;
        }
    }
    //分割图像
    int splitImg(string imgPath,const int AngleL = 120, const int AngleR = 60);
    void setTwoLine(std::vector<cv::Point2f> points)
    {
        line1={points[2].x,points[2].y,points[0].x,points[0].y};
        line2={points[0].x,points[0].y,points[1].x,points[1].y};
        flag=true;
    }
    std::vector<vector<cv::Point>> getFivePoint()
    {
        return pointArr;
    }
private:
    void addfFivePoint(int idx, std::vector<Point>& ptarr);//填充每张图片的五个角点
    void twoPointToStandard(double x1, double y1, double x2, double y2,
                            double& a, double& b, double& c);
    // 求斜截式直线方程的标准式
    void slopeInterceptToStandard(double k, double b, double& a, double& b1, double& c);
    // 求解两条直线的交点
    bool getIntersection(double a1, double b1, double c1,double a2, double b2, double c2,Point2d& pt);
    double GetJointX(cv::Vec4d line, std::vector<double> kb2);
};
#endif // SPLITIMGTOPT_H
